#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() 
{
    int N, V;
    cin >> N >> V;
    vector<int> v(N + 1);
    vector<int> w(N + 1);
    vector<vector<int> > f(N + 1, vector<int>(V + 1));
    for (int i = 1; i <= N; ++i) {
        cin >> v[i] >> w[i];
    }
    
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j <= V; ++j) {
            f[i][j] = f[i - 1][j];
            if (j >= v[i]) {
                f[i][j] = max(f[i][j], f[i - 1][j - v[i]] + w[i]);
            }
        }
    }
    
    cout << f[N][V] << endl;
    return 0;
}